#!/bin/sh

CPATH_SUPPORT=no
COMPILER=$1
VERBOSE=$2
WORKDIR=$3

done=no
cd $3
unset CPATH

# (1) do the test, without CPATH; should fail
if "$COMPILER" -nostdinc -c cpath_test.c 2>/dev/null 1>&2; then
    echo "Compile seems to work even with CPATH not set; assuming CPATH does not work"
    done=0
else
    # (2) do the test, with CPATH set; should pass
    export CPATH=.
    if "$COMPILER" -nostdinc -c cpath_test.c 2>/dev/null 1>&2; then
	CPATH_SUPPORT=yes
    fi
fi
rm -f cpath_test.o

# if done above, assume it works and exit
[ "$done" != "no" ] && exit $done

if [ "$CPATH_SUPPORT" != "yes" ]; then
    [ "$VERBOSE" = "yes" ] && echo "CPATH support not detected"
    exit 0
else
    [ "$VERBOSE" = "yes" ] && echo "CPATH support detected"
    exit 1
fi
